package gmail.pyanoveugen.studyproject.dao;

import gmail.pyanoveugen.studyproject.bean.UserBean;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;

/**
 */
public class UserDao implements ISimpleDao<UserBean> {

    private Connection connection;

    public void setConnection(Connection connection) {
        this.connection = connection;
    }

    public UserDao(){}
    public UserDao(Connection connection) {
        this.connection = connection;
    }

    @Override
    public UserBean find(int id) {
        throw new UnsupportedOperationException("Method hasn't implemented yet.");

    }

    @Override
    public List<UserBean> find(UserBean obj) {
        throw new UnsupportedOperationException("Method hasn't implemented yet.");
    }

    @Override
    public List<UserBean> find() throws SQLException {
        List<UserBean> userBeans = new LinkedList<UserBean>();

        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery("SELECT * FROM users");
        while (resultSet.next()){
            UserBean user = new UserBean();

            String login = resultSet.getString("login");
            String password = resultSet.getString("password");

            user.setLogin(login);
            user.setPassword(password);

            userBeans.add(user);
        }


        return userBeans;
    }

    @Override
    public UserBean save(UserBean obj) {
        throw new UnsupportedOperationException("Method hasn't implemented yet.");
    }

    @Override
    public UserBean remove(int id) {
        throw new UnsupportedOperationException("Method hasn't implemented yet.");
    }

}
